﻿//-----------------------------------------------------------------------

// <copyright file="HeaderFieldDefinition.cs" company="Jamie Knight">

// Copyright (c) Jamie Knight. All rights reserved.

// </copyright>

//-----------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Shapes;

namespace DevKnightlie.WPF.AutoForm.FieldDefinitions
{
    /// <summary>
    /// Field definition which creates a textblock containig static text
    /// </summary>
    /// <remarks>PropertyName can be empty, in which case the Title is used as static text. If Property is not empty then the text is bound to the named property</remarks>
    public class HeaderFieldDefinition: BaseFieldDefinition
    {
        private Rectangle _separatorRectangle;
        #region Private Fields

        #endregion


        #region Properties

        /// <summary>
        /// Sets or returns the Rectangle control used as a separator line
        /// </summary>
        public Rectangle SeparatorRectangle
        {
            get { return _separatorRectangle; }
            private set { _separatorRectangle = value; }
        }

        #endregion


        #region Methods

        public override void BuildInputControl()
        {
            ContentControl container = new ContentControl();
            DockPanel dockPanel = new DockPanel()
            {
                LastChildFill = true
            };
            TextBlock textBlock = new TextBlock()
            {
                VerticalAlignment = System.Windows.VerticalAlignment.Stretch,
                HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
                FontWeight = FontWeights.Bold
            };
            if (!String.IsNullOrWhiteSpace(PropertyName))
            {
                Binding textBinding = new Binding(PropertyName);
                BindingOperations.SetBinding(textBlock, TextBlock.TextProperty, textBinding);
            }
            else
            {
                textBlock.Text = Title;
            }
            SeparatorRectangle = new Rectangle()
            {
                Height = 2,
                HorizontalAlignment = HorizontalAlignment.Stretch,
                Fill = Brushes.LightGray
            };
            dockPanel.Children.Add(SeparatorRectangle);
            DockPanel.SetDock(SeparatorRectangle, Dock.Bottom);
            dockPanel.Children.Add(textBlock);
            container.Content = dockPanel;
            ContainerControl = container;
            InputControl = null;
        }


        public override void BuildLabelControl()
        {
            LabelControl = null;
        }


        #endregion

    }
}
